<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String basePath = "http://" + request.getLocalAddr() + ":"
			+ request.getLocalPort() + request.getContextPath();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<title>${promptInfo.totalDescInfo}</title>
<head>
<script language="javascript" src="<%=request.getContextPath()%>/js/prototype-1.6.0.3.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
	//input验证
	$.formValidator.initConfig({formid:"actionForm",onerror:function(){alert('校验没有通过，具体错误请看错误提示')},onsuccess:function(){}});//表单提交 
	$("#dbcName").formValidator({onshow:"请输入数据库名称",onfocus:"请输入数据库名称",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"数据库名称不能为空,请确认"});
	$("#dbcType").formValidator({onshow:"请选择数据库类型",onfocus:"请选择数据库类型",oncorrect:"选择正确"}).inputValidator({min:1,onerror:"数据库类型不能为空,请确认"});
	$("#dbcIP").formValidator({onshow:"请输入数据库服务器IP",onfocus:"格式例如：000.000.000.000",oncorrect:"输入正确"}).regexValidator({regexp:"ip4",datatype:"enum",onerror:"你输入的IP地址不符合规范"});
	$("#dbcPort").formValidator({onshow:"请输入数据库服务器端口",onfocus:"服务器端口必须为数字",oncorrect:"输入正确"}).regexValidator({regexp:"intege1",datatype:"enum",onerror:"你输入的数据库服务器端口不符合规范"});
	$("#dbcDriverClass").formValidator({onshow:"请输入驱动类路径",onfocus:"请输入驱动类路径",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"驱动类路径不能为空,请确认"});
	$("#dbcAccount").formValidator({onshow:"请输入数据库访问账号",onfocus:"请输入数据库访问账号",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"数据库访问账号不能为空,请确认"});
	$("#dbcPassword").formValidator({onshow:"请输入数据库访问密码",onfocus:"请输入数据库访问密码",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"数据库访问密码不能为空,请确认"});
  	<s:if test="initMap.databaseInfo.dbcType == 5">
  	$("#dbcEncode").formValidator({onshow:"请选择数据库编码",onfocus:"请选择数据库编码",oncorrect:"选择正确"}).inputValidator({min:1,onerror:"数据库编码不能为空,请确认"});
	</s:if>	
  	<s:if test="initMap.databaseInfo.dbcType == 4">
  	$("#dbcServerName").formValidator({onshow:"请输入服务名称",onfocus:"请输入服务名称",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"服务名称不能为空,请确认"});
	</s:if>		
	$("#dbcType").bind("change",function(){
		if ($(this).val() == '5'){
			$("#dbencode").css("display","block");
			$("#sername").css("display","none");
			$("#dbcEncode").formValidator({onshow:"请选择数据库编码",onfocus:"请选择数据库编码",oncorrect:"选择正确"}).inputValidator({min:1,onerror:"数据库编码不能为空,请确认"});
			$("#dbcServerName").formValidator();
		}
		else if ($(this).val() == '4'){
			$("#sername").css("display","block");
			$("#dbencode").css("display","none");
			$("#dbcEncode").formValidator();
			$("#dbcServerName").formValidator({onshow:"请输入服务名称",onfocus:"请输入服务名称",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"服务名称不能为空,请确认"});
		}
		else{
			$("#dbcEncode").val("");
			$("#dbcServerName").val("");
			$("#dbencode").css("display","none");
			$("#sername").css("display","none");
		}
	});

	$("#dbtest").bind("click",function(){
		    $.formValidator.pageIsValid('1');
			$.ajax({
					//ajax请求url
					url:		'ajaxAction.action',
					//ajax提交方式
					type:	    'post',
					//ajax请求超时时长
					timeout:	'60000',
					//ajax请求参数
					data:	$("#actionForm").formSerialize(),
					//请求数据类型，包括json和xml两种
					dataType:	'json',
					//ajax执行前调用函数
					beforeSend:function(request){
					},
					//ajax请求完成后调用函数
					complete:function(request,textStatus){},
					//ajax请求成功调用函数
					success:function(jsonData,textStatus){
						//为ajax请求放回的json格式的数据
						if (textStatus == "success"){
							if(jsonData.success == '1'){
								alert("数据库连接测试成功");
							}
							else{
								alert("数据库连接测试失败");
							}
						}
					},
					//ajax请求错误后调用函数
					error:function(request,textStatus,error){}
			});
	});
});
</script>
</head>
<body >
<form name="actionForm" method="post" action="operateAction.action" id="actionForm">
<input type="hidden" value="dbcName" name="paramMap.logColumn" /> 
<input type="hidden" name="code" value="${code}"> 
<input type="hidden" value="${initMap.databaseInfo.dbcID}" name="paramMap.dbcID" /> 
<input type="hidden" name="imitateStep" value="${pmsIndex.config_database.imitationStep}">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableC">
	<tr>
		<td class="tableCleft">&nbsp;</td>
		<td class="tableCcenter">
		<table width="100%" border="0" cellpadding="0" cellspacing="1" class="SkyTDLine">
			<tr>
				<td class="SkyTDLine">
				<table class="SkyTDLine" cellSpacing="1" cellPadding="0" width="100%" border="0">
					<tr class="MeNewTDLine" align="center">
						<td align="center">
						<table class="Ntable" cellSpacing="1" cellPadding="0" width="100%" border="0">
							<tr class="MeNewTDLine">
								<td align="right" class="SkyTDLine" width="10%">数据库名称：</td>
								<td class="SkyTDLine">
								  <input name="paramMap.dbcName" value="${initMap.databaseInfo.dbcName}" type="text" maxlength="20" id="dbcName" style="width: 200;" />
									&nbsp;<font color="red">*</font><span id="dbcNameTip" style="width:250px"></span>
								</td>
							</tr>
							<tr class="MeNewTDLine">                
								<td align="right" class="SkyTDLine" width="10%">数据库类型：</td>
								<td class="SkyTDLine">
                                <select name="paramMap.dbcType" id="dbcType" style="width: 200;">
								<option value="">请选择数据库类型</option>	
                           		<s:if test="initMap.databaseInfo.dbcType == 1">
								<option value="1" selected="selected">ORACLE数据库</option>	
                           		</s:if>		
								<s:else>
								<option value="1">ORACLE数据库</option>	
								</s:else>
                           		<s:if test="initMap.databaseInfo.dbcType == 2">
								<option value="2" selected="selected">SQL Server数据库</option>	
                           		</s:if>		
								<s:else>
								<option value="2">SQL Server数据库</option>	
								</s:else>	
	                            <s:if test="initMap.databaseInfo.dbcType == 3">
								<option value="3" selected="selected">DB2数据库</option>	
                           		</s:if>		
								<s:else>
								<option value="3">DB2数据库</option>	
								</s:else>	
                           		<s:if test="initMap.databaseInfo.dbcType == 4">
								<option value="4" selected="selected">INFORMIX数据库</option>	
                           		</s:if>		
								<s:else>
								<option value="4">INFORMIX数据库</option>	
								</s:else>	
                           		<s:if test="initMap.databaseInfo.dbcType == 5">
								<option value="5" selected="selected">MY SQL数据库</option>	
                           		</s:if>		
								<s:else>
								<option value="5">MY SQL数据库</option>	
								</s:else>	
								</select>
                                 &nbsp;<font color="red">*</font><span id="dbcTypeTip" style="width:250px"></span></td>
							</tr>
							<tr class="MeNewTDLine">                
								<td align="right" class="SkyTDLine" width="10%">数据库服务器IP：</td>
								<td class="SkyTDLine">
									<input name="paramMap.dbcIP" value="${initMap.databaseInfo.dbcIP}" type="text" maxlength="20" id="dbcIP"  style="width: 200;" />
									&nbsp;<font color="red">*</font><span id="dbcIPTip" style="width:250px"></span>
								</td>
							</tr>
							<tr class="MeNewTDLine">
								<td align="right" class="SkyTDLine" width="10%">数据库服务器端口：</td>
								<td class="SkyTDLine">
								<input name="paramMap.dbcPort" value="${initMap.databaseInfo.dbcPort}" type="text" maxlength="100" id="dbcPort" style="width: 200;" />
								&nbsp;<font color="red">*</font><span id="dbcPortTip" style="width:250px"></span>
								</td>
							</tr>
							<tr class="MeNewTDLine">
								<td align="right" class="SkyTDLine" width="10%">驱动类路径：</td>
								<td class="SkyTDLine">
								<input name="paramMap.dbcDriverClass" value="${initMap.databaseInfo.dbcDriverClass}" type="text" maxlength="50" id="dbcDriverClass" style="width: 200;" />
								&nbsp;<font color="red">*</font><span id="dbcDriverClassTip" style="width:250px"></span>
								</td>
							</tr>
                          	<s:if test="initMap.databaseInfo.dbcType == 5">
								<tbody id="dbencode" style="display:block;">
                          	</s:if>	
							<s:else>
								<tbody id="dbencode" style="display:none;">
							</s:else>	
							<tr class="MeNewTDLine">
								<td align="right" class="SkyTDLine" width="10%">数据库编码：</td>
								<td class="SkyTDLine">
                                <select name="paramMap.dbcEncode" id="dbcEncode" style="width: 200;">
								<option value="">请选择数据库编码</option>	
                           		<s:if test="initMap.databaseInfo.dbcEncode == 'utf8'">
								<option value="utf8" selected="selected">utf8</option>	
                           		</s:if>		
								<s:else>
								<option value="utf8">utf8</option>	
								</s:else>
                           		<s:if test="initMap.databaseInfo.dbcEncode == 'gbk'">
								<option value="gbk" selected="selected">gbk</option>	
                           		</s:if>		
								<s:else>
								<option value="gbk">gbk</option>	
								</s:else>	
	                            <s:if test="initMap.databaseInfo.dbcEncode == 'ISO8859-1'">
								<option value="ISO8859-1" selected="selected">ISO8859-1</option>	
                           		</s:if>		
								<s:else>
								<option value="ISO8859-1">ISO8859-1</option>	
								</s:else>
								</select>
                                &nbsp;<font color="red">*</font><span id="dbcEncodeTip" style="width:250px"></span></td>
							</tr>
                            </tbody>
                          	<s:if test="initMap.databaseInfo.dbcType == 4">
								<tbody id="dbencode" style="display:block;">
                          	</s:if>	
							<s:else>
								<tbody id="dbencode" style="display:none;">
							</s:else>	
							<tr class="MeNewTDLine">
								<td align="right" class="SkyTDLine" width="10%">服务名称：</td>
								<td class="SkyTDLine">
								<input name="paramMap.dbcServerName" value="${initMap.databaseInfo.dbcServerName}" type="text" maxlength="50" id="dbcServerName" style="width: 200;" />
								&nbsp;<font color="red">*</font><span id="dbcServerNameTip" style="width:250px"></span>
							</tr>
							</tbody>
							<tr class="MeNewTDLine">
								<td align="right" class="SkyTDLine">数据库访问账号：</td>
								<td class="SkyTDLine">
								<input name="paramMap.dbcAccount" value="${initMap.databaseInfo.dbcAccount}" type="text" maxlength="50" id="dbcAccount" style="width: 200;" />
								&nbsp;<font color="red">*</font><span id="dbcAccountTip" style="width:250px"></span>
								</td>
							</tr>
							<tr class="MeNewTDLine">
								<td align="right" class="SkyTDLine">数据库访问密码：</td>
								<td class="SkyTDLine">
								<input name="paramMap.dbcPassword" value="${initMap.databaseInfo.dbcPassword}" type="text" maxlength="50" id="dbcPassword" style="width: 200;" />
								&nbsp;<font color="red">*</font><span id="dbcPasswordTip" style="width:250px"></span>
								</td>
							</tr>
							<tr class="MeNewTDLine" align="center">
								<td align="center" colspan="2" class="SkyTDLine">
								<input type="submit" name="BtnOk" value="创建" id="BtnOk" class="SkyButtonBlur" onMouseOut="this.className='SkyButtonBlur'" onMouseOver="this.className='SkyButtonFocus'" />&nbsp;&nbsp;
								<input type="button" id="dbtest" name="BtnOk" value="连接" id="BtnOk" class="SkyButtonBlur" onMouseOut="this.className='SkyButtonBlur'" onMouseOver="this.className='SkyButtonFocus'" />&nbsp;&nbsp;
								<input type="button" name="BtnReturn" value="返回" id="BtnReturn" class="SkyButtonBlur" onMouseOut="this.className='SkyButtonBlur'" onMouseOver="this.className='SkyButtonFocus'" onclick="window.history.back();" />
								</td>
							</tr>
						</table>
						</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</td>
		<td class="tableCright">&nbsp;</td>
	</tr>
</table>
</form>
</body>
</html>
